{% extends "base_page_frame.html" %}
{% load i18n %}
{% block headjs %}
<style>
table th,td{
border-bottom: 1px solid #1E1E1E;
background:#000;	  
color:#ffffff;
}
table th{
color:#b0ffff;
background:#206688;
}
</style>
<script>

maxLine=500;

function formatLine(data)
{
	return "<tr><td>"+data.id+"</td>"+"<td>"+data.PIN+"</td>"
		+"<td>"+data.EName+"</td>"+"<td>"+data.TTime+"</td>"
		+"<td>"+data.State+"</td>"+"<td>"+data.Verify+"</td>"
		+"<td>"+data.Device+"</td></tr>";
}

function refreshLines(data)
{
	var tbl=$("#tblLogList tr");
	var tblLen=tbl.length;
	var remove=tblLen+data.length-maxLine;
	for(var i=0; i<remove; i++) $(tbl[tblLen-1-i]).remove();
	if(remove>0) tblLen-=remove;
	if(tblLen<=0)
	{
		var lines=[]
		for(var i=0; i<data.length && i<maxLine; i++) lines.push(formatLine(data[i]));
		$("#tblLogList").html(lines.join("\n"));
		return;
	}
	for(var i=0; i<data.length; i++)
		$(tbl[0]).before(formatLine(data[i]));
}

lastId=0;

function checkTime(i)
{
	if (i<10) 
  		{i="0" + i}
	return i
}

function timeStr()
{
	var today=new Date()
	var h=today.getHours()
	var m=today.getMinutes()
	var s=today.getSeconds()
	return checkTime(h)+":"+checkTime(m)+":"+checkTime(s)
}

function getNewTrans()
{
	$.ajax({type: "GET", 
			url: "?lastid="+lastId, 
			dataType:"json",
			success: function(data){
					if(data.ret>0)
					{	
						$("#net_info").html(timeStr()+": {%trans "取到"%} "+(data.ret)+" {%trans "新记录"%}")
						lastId=data.lastId;
						refreshLines(data.data);
					}
					else
						$("#net_info").html(timeStr()+":{%trans "无新记录"%}")
					setTimeout("getNewTrans()", 2000);
				},
			error: function(obj, msg, exc){
					$("#net_info").html(timeStr()+"{%trans "访问最后的数据错误！"%}："+obj+", MSG="+msg);
					setTimeout("getNewTrans()", 20000);
				}
			});
}

$(function(){
	$().ajaxStart(function(){
		$("#id_loading").show();
		});
	getNewTrans();
})
</script>
{% endblock %}

{% block datalist_content %}
<div width="100%">
<p id="net_info" style="margin-top: 23px; margin-left: 0px;"></p>

<table width="100%"><tr><th>{%trans 'id'%}</th><th>{%trans '考勤号码'%}</th><th>{%trans '姓名'%}</th>
	<th>{%trans '考勤时间'%}</th><th>{%trans '考勤状态'%}</th>
	<th>{%trans '验证方式'%}</th><th>{%trans '设备管理'%}</th></tr>
</thead>
<tbody id="tblLogList">
</tbody>
</table>
</div>
<br />
<p>&nbsp;</p>

{% endblock %}
